#ifndef __MARS_GRAPHICS_SHADER_MGR_H__
#define __MARS_GRAPHICS_SHADER_MGR_H__

#include "MarsObject.h"
#include "MarsShaderCompiler.h"
#include "MarsShaderType.h"

using namespace Core;

namespace Graphics
{

class Shader;

class ShaderMgr : public Object
{
public:
									~ShaderMgr();
	
	bool							Initialize();
	void							Shutdown();

	static ShaderMgr&				Instance();
	static void						Destroy();

	Shader*							LoadShader( ShaderType eType, const char* pcszFileName, const char* pcszEntry, const char* pcszShaderModel );
	Shader*							GetShader( uint32 hash );
	const Shader*					GetShader( uint32 hash ) const;

private:
									ShaderMgr();
									ShaderMgr( const ShaderMgr& );
	ShaderMgr&						operator = ( const ShaderMgr& );

	static ShaderMgr*				ms_pShaderMgr;

private:
	ShaderCompiler					m_shaderCompiler;

	typedef std::map< uint32, Shader* > ShaderMap;
	typedef ShaderMap::iterator ShaderMapItr;
	typedef ShaderMap::const_iterator ShaderMapConstItr;

	ShaderMap						m_mapShaders;
};

inline ShaderMgr& ShaderMgr::Instance()
{
	if ( !ms_pShaderMgr )
	{
		ms_pShaderMgr = new ShaderMgr();
	}

	return ( *ms_pShaderMgr );
}

inline Shader* ShaderMgr::GetShader( uint32 hash )
{
	ShaderMapItr it = m_mapShaders.find( hash );
	return it != m_mapShaders.end() ? it->second : NULL;
}

inline const Shader* ShaderMgr::GetShader( uint32 hash ) const
{
	ShaderMapConstItr it = m_mapShaders.find( hash );
	return it != m_mapShaders.end() ? it->second : NULL;
}

} // end of namespace Graphics

#endif // end of #ifndef __MARS_GRAPHICS_SHADER_MGR_H__